//implement practice_11_7
#include "chapter11_practice7_complex0.h"

Complex::Complex()
{
	real = imaginary = 0.0;
}

Complex::Complex(double a, double b)
{
	real = a;
	imaginary = b;
}

Complex Complex::operator+(const Complex & a) const
{
	return Complex(real + a.real, imaginary + a.imaginary);
}

Complex Complex::operator-(const Complex & a) const
{
	return Complex(real - a.real, imaginary - a.imaginary);
}

Complex Complex::operator*(const Complex & a) const
{
	return Complex(real * a.real- imaginary * a.imaginary, 
		real *a.imaginary+imaginary*a.real);
}

Complex Complex::operator~() const
{
	return Complex(-real, -imaginary);
}

Complex operator*(double n, const Complex & a)
{
	return Complex(n*a.real, n*a.imaginary);
}

std::ostream &operator<<(std::ostream & os, const Complex & c)
{
	os << "(" << c.real << "," << c.imaginary << "i)";
	return os;
}

std::istream &operator>>(std::istream & is, Complex & c)
{
	std::cout << "real: ";
	if (is >> c.real)
	{
		std::cout << "imaginary: ";
		is >> c.imaginary;
	}
	return is;
}